#include "Sheet.h"
#include<string>
#include<map>
#include<vector>

typedef std::map<int, Entry*>::iterator EMIter;

class EntryIterImpl : public EntryIter
{
public:
	EntryIterImpl(EMIter cur, EMIter end);
	EntryIterImpl(EMIter end);
	virtual bool Next();
	virtual void Release();
	virtual Entry* GetEntry();

	virtual bool operator==( const EntryIter& rhs );
	virtual bool operator!=( const EntryIter& rhs );


private:
	EMIter m_iterCur;
	EMIter m_iterEnd;
};

class SheetImpl : public Sheet
{
public:
	SheetImpl(const char* memdata, int size);
	~SheetImpl();
	virtual Entry*		GetEntry(int id);
	virtual int			GetType(int column);
	virtual const char*	GetTitle(int column);
	virtual int			GetColumn(const char* title);
	virtual int			GetIDColumn();
	virtual int			GetColumnCount();

	virtual EntryIter*	GetFirst();
	virtual EntryIter*	GetLast();


	bool IsLoaded();
private:
	bool ParseSheetData(const char* memdata, int size);
	bool ParseSheetTitle(const char* memdata, int size);
	bool ParseSheetEntry(const char* memdata, int size, int line);
	struct Title
	{
		std::string name;
		int type;
	};

	bool	m_hasID;
	bool	m_isLoaded;
	int		m_idColumn;

	std::vector<Title*> m_titles;

	
	std::map<int, Entry*> m_entrys;

	//typedef std::map<std::string, Title*>::iterator TMItor;
	//std::map<std::string, Title*> m_titleMap;
};


Sheet* CreateSheet(const char* memdata, int size);